package pl.grabar.clinic.client.web.actions.user;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import pl.grabar.clinic.core.dao.Dao;
import pl.grabar.clinic.core.domain.person.User;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

@Actions({ @Action(""), @Action("list"), @Action("/a"), @Action("aa") })
 @InterceptorRef("defaultStack")
@Results({ @Result(name = "success", location = "index.jsp"), @Result(name = "input", location = "list.jsp") })
public class NewUserAction extends ActionSupport implements Preparable {

	private static final long serialVersionUID = 6765775322885351932L;

	@Autowired
	Dao<User> userDao;
	
	@Override
	public void prepare() throws Exception {
		
		if(userDao==null){
			System.out.println("blad");
		}
		System.out.println("start");
		User user = new User();
		user.setLastName("dom");
		user.setLogin("ssss");
		user.setFirstName("olsanxio");
//		entityManagerFactoryService.getEntityManag().getTransaction().begin();
//		entityManagerFactoryService.getEntityManag().persist(user);
//		entityManagerFactoryService.getEntityManag().getTransaction().commit();
//		entityManagerFactoryService.closeEMF();
		userDao.save(user);
		System.out.println("koniec");
	}

	@Override
	public void validate() {
	}

	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
	
}
